import request from '@/utils/request'

enum Api {
  list = '/patrolPointCamera/loadList',
  save = '/patrolPointCamera/add',
  edit = '/patrolPointCamera/update',
  delete = '/patrolPointCamera/delete',
  upload = '',
  import = '',
  export = ''
}

/**
 * 导入Xlsx/Json
 * @param data
 */
export const importFile = async (data: FormData) => {
  return await request.post(Api.import, {
    data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 列表
 * @param data
 */
export const list = async (data: {
  pageNum: number
  pageSize: number
  name?: undefined | string
  deviceName?: undefined | string
  partName?: undefined | string
}) => {
  return await request.post(Api.list, { data })
}

/**
 * 新增/修改
 * @param data
 * @param isUpdate true 修改 / false 新增
 */
export const save = async (
  data: {
    id?: undefined | string
    isMultiplePatrol?: string | number
    partId?: undefined | string
    partName: string
    deviceId: string
    deviceName: string

    nvrId?: undefined | number | string
    cameraId?: undefined | number | string
    positionNum?: undefined | number | string
    positionName?: undefined | string
    positionPic?: string
    threeDimensionalParam?: number | string
    algInstance?: string
    algType?: string
    floor?: number | string
    upper?: number | string
  },
  isUpdate: boolean
) => {
  const url = isUpdate ? Api.edit : Api.save
  return await request.post(url, { data })
}

/**
 * 修改
 * @param data
 */
export const edit = async (data: {
  id?: undefined | number | string
  isMultiplePatrol?: undefined | number | string
}) => {
  return await request.post(Api.edit, { data })
}

/**
 * 删除
 * @param id
 */
export const delOne = async (params: { id: number }) => {
  return await request.delete(Api.delete, { params })
}

/**
 * 巡视点位-二级设备
 * @param
 */
export const device = async () => {
  return await request.get('/patrolPointCamera/loadSecondDeviceDTOList')
}

/**
 * 巡视点位-NVR
 * @param
 */
export const nvr = async () => {
  return await request.get('/nvr/getNvrList')
}

/**
 * 巡视点位-摄像机
 * @param
 */
export const camera = async (params: { nvrId: number }) => {
  return await request.get('/camera/getByNvrId', { params })
}

/**
 * 巡视点位-预置位
 * @param
 */
export const point = async (params: { nvrIp: string; cameraIp: string }) => {
  return await request.get('/patrolPointCamera/loadPositionInfoDTOList', {
    params
  })
}

/**
 * 巡视点位-抓拍图片
 * @param
 */
export const pointCamera = async (params: {
  nvrIp: string
  nvrPort: string
  nvrUsername: string
  nvrPassword: string
  manufacturer: string
  passNum: string
  positionNum: string
}) => {
  return await request.post('/patrolPointCamera/captureJpeg', {
    data: params
  })
}

/**
 * 巡视点位-算法类型
 * @param
 */
export const algType = async () => {
  return await request.get('/patrolPointCamera/getAlgTypeList')
}

/**
 * 巡视点位-算法类型
 * @param
 */
export const byAlgType = async (params: { algType: string }) => {
  return await request.get('/patrolPointCamera/getAlgCategoryByAlgType', {
    params
  })
}

/**
 * 巡视点位-详情修改
 * @param data
 */
export const updateDetail = async (data: {
  id: undefined | number | string
  nvrId?: undefined | number | string
  cameraId?: undefined | number | string
  positionNum?: undefined | number | string
  positionName?: undefined | string
  positionPic?: string
  threeDimensionalParam?: number | string
  algInstance?: string
  algType?: string
  floor?: number | string
  upper?: number | string
}) => {
  return await request.post('/patrolPointCamera/updateDetailInfo', { data })
}

/**
 * 修改映射视场角度
 * @param data
 */
export const editAngle = async (data: {
  id: number | string
  threeDimensionalParam: undefined | string
}) => {
  return await request.post('/patrolPointCamera/update', {
    data
  })
}
